﻿using System;

namespace Demo.OData.CustomService
{
  //Adding parameterless constructor
  public partial class CustomContext
  {
    // It builds a relative address to OData Service in the same web.
    private static Uri CreateURI()
    {
      Uri res = null;
      if(System.ComponentModel.DesignerProperties.IsInDesignTool) {
        res = new Uri("http://localhost/test.svc"); //Design mode. Constructor needs some URL. It doesn't work, 
      } else {
        int idx = App.Current.Host.Source.AbsoluteUri.IndexOf("/ClientBin");
        res = new Uri(App.Current.Host.Source.AbsoluteUri.Substring(0, idx) + "/CustomService.svc");
      };
      return res;
    }
    //Constructor
    public CustomContext() : this(CustomContext.CreateURI())
    {
    }
  }
}
